<?php abstract class XReq {
	protected static $Arrays = array ('_SESSION', '_COOKIE', '_GET', '_POST');

	protected static function _Caller () {
		$Caller = debug_backtrace ();
		foreach ($Caller as $Elem) if (isset ($Elem ['class']) and __CLASS__ !== $Elem ['class']) return ($Elem ['class']);
		return (NULL);
	}
	protected static function _Write ($Class, $Name, $Value) {
		$_SESSION [$Class][$Name] = $Value;
		return (TRUE);
	}
	protected static function _Push ($Class, $Name, $Value) {
		if (isset ($_SESSION [$Class][$Name]) and ! is_array ($_SESSION [$Class][$Name])) return (FALSE);
		isset ($_SESSION [$Class][$Name]) or $_SESSION [$Class][$Name] = array ();
		array_push ($_SESSION [$Class][$Name], $Value);
		return (TRUE);
	}
	protected static function _Drop ($Class, $Name) {
		foreach (self::$Arrays as $Array) if (isset ($GLOBALS [$Array][$Class]) and isset ($GLOBALS [$Array][$Class][$Name])) unset ($GLOBALS [$Array][$Class][$Name]);
	}
	protected static function _Fetch ($Class, $Name) {
		$Result = NULL;
		foreach (self::$Arrays as $Array) isset ($GLOBALS [$Array][$Class]) and isset ($GLOBALS [$Array][$Class][$Name]) and $Result = $GLOBALS [$Array][$Class][$Name];
		return ($Result);
	}
	protected static function _FetchDrop ($Class, $Name) {
		$Result = self::_Fetch ($Class, $Name);
		self::_Drop ($Class, $Name);
		return ($Result);
	}

	public static function Write ($Name, $Value) {
		if (! $Caller = self::_Caller ()) return (FALSE);
		return (self::_Write ($Caller, $Name, $Value));
	}
	public static function Push ($Name, $Value) {
		if (! $Caller = self::_Caller ()) return (FALSE);
		return (self::_Push ($Caller, $Name, $Value));
	}
	public static function Drop ($Name) {
		if (! $Caller = self::_Caller ()) return (NULL);
		return (self::_Drop ($Caller, $Name));
	}
	public static function Fetch ($Name) {
		if (! $Caller = self::_Caller ()) return (NULL);
		return (self::_Fetch ($Caller, $Name));
	}
	public static function FetchDrop ($Name) {
		if (! $Caller = self::_Caller ()) return (NULL);
		return (self::_FetchDrop ($Caller, $Name));
	}

	public static function Record ($Msg) {
		$Caller = self::_Caller () or $Caller = 'ANONYMOUS';
		self::_Push (__CLASS__, 'Msg', "$Caller: $Msg");
	}
	public static function Messages () {return (self::_FetchDrop (__CLASS__, 'Msg'));}
} ?>